import json

import graphene
from fastapi import FastAPI
from starlette.graphql import GraphQLApp

# 生成gql的Query
class Query(graphene.ObjectType):
    hello = graphene.String(name=graphene.String(default_value="stranger"))

    def resolve_hello(self, info, name):
        return "Hello " + name

    login_in = graphene.String(username=graphene.String(default_value="administrator"))

    def resolve_login_in(self, info, username):
        return "Hello " + username

    login = graphene.String(username=graphene.String(default_value="administrator"))
    graphene.ObjectType

    def resolve_login(self, info, username):

        name = '李甲'
        if(name.__eq__(username)):
            data = [{'username': '李甲', 'b': 2, 'c': 3, 'd': 4, 'e': 5}]

            json2 = json.dumps(data)

            return json2
        else :
            return ""


app = FastAPI()
app.add_route("/", GraphQLApp(schema=graphene.Schema(query=Query)))
